package me.zhengjie.pm.projecttask.rest;

import me.zhengjie.aop.log.Log;
import me.zhengjie.pm.projecttask.domain.ProjectAllTaskView;
import me.zhengjie.pm.projecttask.service.ProjectAllTaskViewService;
import me.zhengjie.pm.projecttask.service.dto.ProjectAllTaskViewQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author yuxj
* @date 2020-04-14
*/
@Api(tags = "全部任务视图管理")
@RestController
@RequestMapping("/api/projectAllTaskView")
public class ProjectAllTaskViewController {

    private final ProjectAllTaskViewService projectAllTaskViewService;

    public ProjectAllTaskViewController(ProjectAllTaskViewService projectAllTaskViewService) {
        this.projectAllTaskViewService = projectAllTaskViewService;
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('projectAllTaskView:list')")
    public void download(HttpServletResponse response, ProjectAllTaskViewQueryCriteria criteria) throws IOException {
        projectAllTaskViewService.download(projectAllTaskViewService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询全部任务视图")
    @ApiOperation("查询全部任务视图")
    @PreAuthorize("@el.check('projectAllTaskView:list')")
    public ResponseEntity<Object> getProjectAllTaskViews(ProjectAllTaskViewQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(projectAllTaskViewService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增全部任务视图")
    @ApiOperation("新增全部任务视图")
    @PreAuthorize("@el.check('projectAllTaskView:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody ProjectAllTaskView resources){
        return new ResponseEntity<>(projectAllTaskViewService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改全部任务视图")
    @ApiOperation("修改全部任务视图")
    @PreAuthorize("@el.check('projectAllTaskView:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody ProjectAllTaskView resources){
        projectAllTaskViewService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除全部任务视图")
    @ApiOperation("删除全部任务视图")
    @PreAuthorize("@el.check('projectAllTaskView:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody String[] ids) {
        projectAllTaskViewService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}